﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using WalkingTec.Mvvm.Core;
using WalkingTec.Mvvm.Core.Extensions;
using Microsoft.EntityFrameworkCore;
using System.ComponentModel.DataAnnotations;
using SelfService.Model.Models;


namespace SelfService.ViewModel.SysDoctorVMs
{
    public partial class SysDoctorListVM : BasePagedListVM<SysDoctorView, SysDoctorSearcher>
    {

        protected override IEnumerable<IGridColumn<SysDoctorView>> InitGridHeader()
        {
            return new List<GridColumn<SysDoctorView>>{
                this.MakeGridHeader(x => x.Code),
                this.MakeGridHeader(x => x.Name),
                this.MakeGridHeader(x => x.RoomName),
                this.MakeGridHeader(x => x.DepartmentName),
                this.MakeGridHeader(x => x.Photo),
                this.MakeGridHeader(x => x.DoctorLevel),
                this.MakeGridHeader(x => x.Info),
                this.MakeGridHeader(x => x.TotalFee),
                this.MakeGridHeader(x => x.ExamFee),
                this.MakeGridHeader(x => x.ClinicFee),
                this.MakeGridHeader(x => x.Workday),
                this.MakeGridHeader(x => x.WorkTime),
                this.MakeGridHeaderAction(width: 200)
            };
        }

        public override IOrderedQueryable<SysDoctorView> GetSearchQuery()
        {
            var query = DC.Set<SysDoctor>()
                .CheckContain(Searcher.Code, x=>x.Code)
                .CheckContain(Searcher.Name, x=>x.Name)
                .CheckEqual(Searcher.RoomId, x=>x.RoomId)
                .CheckContain(Searcher.DoctorLevel, x=>x.DoctorLevel)
                .Select(x => new SysDoctorView
                {
				    ID = x.ID,
                    Code = x.Code,
                    Name = x.Name,
                    RoomName = x.Room.Name,
                    DepartmentName = x.Room.DepartmentName,
                    Photo = x.Photo,
                    DoctorLevel = x.DoctorLevel,
                    Info = x.Info,
                    TotalFee = x.TotalFee,
                    ExamFee = x.ExamFee,
                    ClinicFee = x.ClinicFee,
                    Workday = x.Workday,
                    WorkTime = x.WorkTimeIntervals.Select(y => y.TimeInterval.Name).ToSepratedString(null,","), 
                })
                .OrderBy(x => x.ID);
            return query;
        }
    }

    public class SysDoctorView : SysDoctor{
        [Display(Name = "科室")]
        public String DepartmentName { get; set; }
        [Display(Name = "工作时段")]
        public String WorkTime { get; set; }
        [Display(Name = "诊室")]
        public String RoomName { get; set; }


    }
}
